package com.uniledger.exchange.bank.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.uniledger.exchange.base.fragment.BaseFragment;

import butterknife.ButterKnife;

public abstract class CardFragment extends BaseFragment implements View.OnClickListener {

    protected OnCardListener listener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnCardListener) {
            listener = (OnCardListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(getViewResourceId(), container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (listener != null) {
            listener.getButton().setOnClickListener(this);
        }
    }

    public abstract int getViewResourceId();

    @Override
    public void onDetach() {
        super.onDetach();
        listener = null;
    }
}
